package cool.lichuan.project.common;

import com.wf.captcha.base.Captcha;
import com.wf.captcha.utils.CaptchaUtil;
import cool.lichuan.common.util.CaptchaTypeUtil;
import cool.lichuan.framework.config.AdminConfig;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author lichuan
 * @date 2021/11/24 13:26
 * @description
 */
@Controller
@RequiredArgsConstructor
public class CaptchaController {
    private final AdminConfig adminConfig;

    @GetMapping("/captcha")
    public void captcha(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Captcha captcha = CaptchaTypeUtil.getCaptcha(adminConfig.getCaptchaType());
        CaptchaUtil.out(captcha, request, response);
    }
}
